//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Microsoft.Research.DataLayer
{
    public interface IConnMgrInfoParams
    {
        Guid ID { get; }
        string Name { get; }
    }

    public interface IConnMgrInfoParamsHelper
    {
        IConnMgrInfoParams FromXml(datasource.DataSource dataSource);
        datasource.DataSource ToXml(IConnMgrInfoParams preset);
        bool HandlesConnection(IConnMgrInfoParams conn);
        Connection OpenConnection(IConnMgrInfoParams conn);
        bool TestConnection(IConnMgrInfoParams conn, out BackendStorageException error);
    }


    public class ConnectionParametersBase : IConnMgrInfoParams
    {
        private Guid id;
        private string name;
        private Dictionary<string, object> paramList;

        protected ConnectionParametersBase(Guid id, string name)
        {
            this.id = id;
            this.name = name;
            paramList = new Dictionary<string, object>();
        }

        #region IConnMgrInfoParams Members

        public Guid ID
        {
            get { return id; }
            protected set { id = value; }
        }

        public string Name
        {
            get { return name; }
            protected set { name = value; }
        }

        #endregion

        protected Dictionary<string, object> Parameters
        {
            get { return paramList; }
        }

        public override string ToString()
        {
            return string.Format("{0}: {1} ({2})", this.GetType().Name, Name, ID);
        }
    }
}
